-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Go to next/prev file in same dir as current file #14705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
book/src/keymap.md
Outdated
| | `['` | Go to the next file alphabetically in the current file's directory | `goto_next_file` | | ||
| | `]'` | Go to the previous file alphabetically in the current file's directory | `goto_prev_file` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
['/]' could alternatively be nice to use for a feature that goes to the next/prev entry in the last picker (<space>'). I'm not sure what to recommend for the binding in ]/[ for this feature...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm picking [n, ]n.
helix-term/src/lib.rs
Outdated
| } | ||
|
|
||
| /// Get the parent dir if it exists. | ||
| fn parent_dir(editor: &mut Editor) -> Option<PathBuf> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor style thing: I'd prefer that this live in helix-term/src/commands.rs rather than top-level here, since it's only used as a helper for a few commands
helix-term/src/commands.rs
Outdated
| let found = editor | ||
| .documents | ||
| .values() | ||
| .find(|doc| doc.path().map_or(false, |p| p == file)) | ||
| .map(|doc| doc.id()); | ||
| if let Some(id) = found { | ||
| editor.switch(id, Action::Replace); | ||
| } else if let Err(e) = editor.open(file, Action::Replace) { | ||
| editor.set_error(format!("Open file failed: {:?}", e)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Editor::open already looks through open documents and switches if the document exists, so this block can be replaced with just the call to Editor::open
helix-term/src/commands.rs
Outdated
| Some(value) => value, | ||
| None => return, | ||
| }; | ||
| let (_, doc) = current_ref!(editor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let (_, doc) = current_ref!(editor); | |
| let doc = doc!(editor); |
helix-term/src/commands.rs
Outdated
| goto_next_file_impl(cx.editor, Direction::Backward, cx.count()); | ||
| } | ||
|
|
||
| fn goto_next_file_impl(editor: &mut Editor, direction: Direction, count: usize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nicer to have this function (and parent_dir) return an anyhow::Result. Then the typed commands can return that as-is. And the other callers can say:
if let Err(err) = goto_next_file_impl(...) {
editor.set_error(err);
}`[n` and `]n` implement the unimpaired mappings: > [f Go to the file preceding the current one alphabetically in the current file's directory. > ]f Go to the file succeeding the current one alphabetically in the current file's directory. that are already taken.
This implements unimpaired mappings: